<template>
	<!--<el-dialog :title="title" :visible.sync="formVisible">-->
	<div id="dic_detail" class="table" v-show="formVisible">
		<div class="container">
			<div style="text-align:center;">
				<div style="text-align:left; margin:0 auto;">
					<el-form :model="modelData" label-width="100px" class="demo-ruleForm">
						<template>
							<el-form-item label="类型" v-if="modelData.id == 0 || modelData.id == null">
								<el-select v-model="modelData.dictCategoryId" placeholder="选择类别" class="handle-select mr10" disabled>
									<el-option v-for="item in dicTypes" :key="item.id" :label="item.dictCategoryDesc" :value="item.id"></el-option>
								</el-select>
							</el-form-item>
							<el-form-item label="类型" v-else>
								<el-select v-model="modelData.dictCategoryId" placeholder="选择类别" class="handle-select mr10" disabled>
									<el-option v-for="item in dicTypes" :key="item.id" :label="item.dictCategoryDesc" :value="item.id"></el-option>
								</el-select>
							</el-form-item>
						</template>
						<template>
							<el-form-item label="编码" v-if="modelData.id">
								<el-input v-model="modelData.dictKey" :max="10" placeholder="请输入编码" :disabled="true" ></el-input>
							</el-form-item>
							<el-form-item label="编码" v-else>
								<el-input v-model="modelData.dictKey" :max="10" placeholder="请输入编码" ></el-input>
							</el-form-item>
						</template>
						<el-form-item class="role_area" label="协议文件：">
								<el-upload class="upload-demo" ref="upload" :action="globaldata.uploadUrl"  :limit="1"  :on-success="handleAvatarSuccess1" :on-remove="handleRemove">
									<el-button size="small" type="primary">点击上传</el-button>
								</el-upload>
						</el-form-item>
						<el-form-item label="内容">
							<template v-if="isAddable==false">
								<UE :defaultMsg="modelData.dictValue" id="ue1" ref="ue" ></UE>
							</template>
							<template v-else>
								<el-input type="textarea" v-model="modelData.dictValue" :maxlength="50" placeholder="请输入内容">
								</el-input>
							</template>
						</el-form-item>
						<el-form-item label="排序">
							<el-input-number v-model="modelData.seqNo" :min="1" :max="10"></el-input-number>
						</el-form-item>
					</el-form>
				</div>
			</div>
			<div slot="footer" class="dialog-footer my_flex_right">
				<el-button @click="close()">返回</el-button>
				<el-button type="primary" @click="save()">保存</el-button>
			</div>
		</div>
	</div>
</template>

<script>
	import UE from '../../../common/wangEditor.vue';
	import service from '../../../../js/common/dicservice.js';
	export default {
		props: {
			id: 0,
			parentDetailData: {},
			dicTypes: {
				type: Array
			},
			isAddable: null,
			dictCategoryId: 0
		},
		components: {
			UE
		},
		data() {
			return {
				modelData: {},
				formVisible: false,
			}
		},
		watch: {
			formVisible(newVal, oldVal) {		
				if(newVal) {
					this.resetData();
					service.getModelData(this,this.id);
				}
			},
		},
		methods: {
			resetData() {
				this.modelData = {
					dictCategoryId: this.dictCategoryId,
					dictKey: null,
					seqNo: null,
					createTime: null,
					updateTime: null,
					dictValue: ""
				}
			},
			show() {
				this.formVisible = true;
			},
			save() {
				if(this.isAddable==false){
					this.modelData.dictValue = this.$refs.ue.getUEContent();
					this.modelData.dictValue = this.modelData.dictValue.replace("<p><br></p>", "");
				}
				service.handleSave(this);
			},
			close() {
				this.parentDetailData.isTabelShow = true;
				this.formVisible = false;
			},
			handleAvatarSuccess1(files) {
				this.modelData.dictValue = files.data.fullUrl;
				this.$refs.upload.clearFiles()
			},
			handleRemove(file, fileList) {
                this.modelData.dictValue = null;
			},
		}
	}
</script>
<style lang="less" scoped="scoped">
	#dic_detail {
		.el-popper {
			z-index: 200008 !important;
		}
	}
</style>